import Hello from '../Hello.vue?t=23223'


    function update(data){
        var url = "/trade/update";
        if(data.splice) url = "/trade/updatebatch";

        axios.post(url, data).then(function (response) {
            console.log("response",response)
            loadData();
        }).catch(function (error) {
            console.log("error",error);
            loadData();
        });
    }

var tradeStatusList = [
{id:-1,name:"已删除"},
{id:0,name:"编辑中"},
{id:4,name:"已下单"},
{id:5,name:"拼版中"},
{id:6,name:"已拼版"}];

const { createApp } = Vue;
    var app = createApp({
    data() {
      return {
        list:[], shopList:[],
        currentIndex : -1,
        selector:{target:{},statusList:[4,5],withGroupList:1},
        statusList:tradeStatusList,
        intBools:[{id:0,name:"否"},{id:1,name:"是"}]
      }
    },methods:{
        submit:function (index){
            var data = this.list[index] || this.list;
            update(data);
        }, order:function (id){
            axios.post("/trade/order", {id:id}).then(function (response) {
                loadData();
            }).catch(function (error) {
                console.log("error",error);
                loadData();
            });
        },getShop:function (shopId){
            for(var i = 0; i < this.shopList.length;i++){
                if(shopId == this.shopList[i].id) return this.shopList[i];
            }
            return null;
        },getStatus:function (id){
            for(var i = 0; i < this.statusList.length;i++){
                if(id == this.statusList[i].id) return this.statusList[i];
            }
            return null;
        }
     },
    watch:{
        selector:{
            handler:function(nv,ov){
                loadData()
            },deep:true
        }
    }, components: {
        Hello
      }
  }).mount('#app');


function loadData( ){
    var selector = app.$data.selector || {}
    axios.post('/trade/list', selector).then(function (response) {
        console.log("/trade/list",response.data.data)
        app.$data.list = response.data.data || [];
    }).catch(function (error) {
        console.log("error",error);
    });
}

function loadShopData( ){
    axios.post('/shop/list', {}).then(function (response) {
        app.$data.shopList = response.data.data;
    }).catch(function (error) {
        console.log("error",error);
    });
}
window.onload=function(){
   console.log("AAAAAAAAAAAAAAAAAAAAAAAA")
   loadShopData();
   loadData( );
}


export { loadData,app}

